home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / misc / gethelp / source / gui.c < prev    next >
C/C++ Source or Header  |  1999-06-14  |  5KB  |  131 lines

  1. #include "gui.h"
  2.  
  3. #include <inline/muimaster.h>
  4.  
  5. struct Library *MUIMasterBase;
  6.  
  7. /*************************/
  8. /* Init & Fail Functions */
  9. /*************************/
  10.  
  11. static VOID fail(APTR app,char *str)
  12. {
  13.         if (app)
  14.                 MUI_DisposeObject(app);
  15.  
  16.         if (MUIMasterBase)
  17.                 CloseLibrary(MUIMasterBase);
  18.  
  19.         if (str)
  20.         {
  21.                 puts(str);
  22.                 exit(20);
  23.         }
  24.         exit(0);
  25. }
  26.  
  27.  
  28. static void init(void)
  29. {
  30.         if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  31.                 fail(NULL,"Failed to open "MUIMASTER_NAME".");
  32. }
  33.  
  34. /************************/
  35. /* DisposeApp           */
  36. /************************/
  37. void DisposeApp(struct ObjApp * App)
  38. {
  39.         MUI_DisposeObject(App->app);
  40.         FreeVec(App);
  41. }
  42.  
  43. /************************/
  44. /* CreateGUI            */
  45. /************************/
  46.  
  47. struct ObjApp *creategui (void)
  48. {
  49.         struct ObjApp *App;
  50.  
  51.         init();
  52.  
  53.         if (!(App = AllocVec(sizeof(struct ObjApp), MEMF_ANY|MEMF_CLEAR))) return(NULL);
  54.  
  55.         /* Create the application object */
  56.            App->app = ApplicationObject,
  57.                 /* Default information */
  58.                 MUIA_Application_Title      , "MUI_Search",
  59.                 MUIA_Application_Version    , "$VER: Demo 1.0 (18.01.99)",
  60.                 MUIA_Application_Copyright  , ")1999, Brendan Rogers",
  61.                 MUIA_Application_Author     , "Brendan Rogers",
  62.                 MUIA_Application_Description, "Search string GUI.",
  63.                 MUIA_Application_Base       , "DEMO",
  64.  
  65.                 /* Define a window object*/
  66.                 SubWindow, App->window = WindowObject,
  67.                         /* Put a title on your window */
  68.                         MUIA_Window_Title, "Search entire document",
  69.                         /* Give your window a unique ID */
  70.                         MUIA_Window_ID   , MAKE_ID('D','E','M','O'),
  71.  
  72.                         /* Define what is inside your window */
  73.                         WindowContents, VGroup, /* Everything inside this group will be layed out vertically */
  74.                             Child, HGroup,
  75.                                 Child, App->label1        = Label ("Match whole word:"),
  76.                                 Child, App->checkmark1    = CheckMark(TRUE),
  77.                                 Child, HSpace (0),
  78.                                 Child, App->label2        = Label ("case sensitive:"),
  79.                                 Child, App->checkmark2    = CheckMark(FALSE),
  80.                                 End,
  81.                             Child, HGroup,
  82.                                 Child, App->label3        = Label ("Search text"),
  83.                                 Child, App->string1       = String ("Enter search text here",30),
  84.                                 MUIA_FixWidth, (ULONG)240,
  85.                                 End,
  86.                             Child, HGroup,
  87.                                 Child, App->simplebutton1 = SimpleButton ("Search"),
  88.                                 Child, HSpace (4),
  89.                                 Child, App->simplebutton2 = SimpleButton ("Cancel"),
  90.                                 End,
  91.                             End,
  92.                         End,
  93.                 End;
  94.  
  95.         /* Check to see if the interface was made, if it wasn't, exit */
  96.         if (!App->app) {
  97.             FreeVec(App);
  98.             fail(App->app,"Failed to create Application.");
  99.         }
  100.  
  101.         /* Shut down the application when the user closes the window, connect the close window gadget to make it */
  102.         /* return MUIV_Application_ReturnID_Quit to out main loop */
  103.         DoMethod(App->window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,App->app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  104.  
  105.         /* shut down the application with the cancel button */
  106.         DoMethod(App->simplebutton2,MUIM_Notify,MUIA_Pressed,FALSE,App->app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  107.  
  108.         /* user hits the search button */
  109.         DoMethod(App->simplebutton1,MUIM_Notify,MUIA_Pressed,FALSE,App->app,2,MUIM_Application_ReturnID,GO_SEARCH);
  110.  
  111.         /* Add my objects to a cyclechain so a user can use the tab key to cycle through my app */
  112.         DoMethod(App->window,MUIM_Window_SetCycleChain,App->checkmark1,App->checkmark2,App->string1,App->simplebutton1,App->simplebutton2,NULL);
  113.  
  114.         /* Help text for bubbles, normally this should be localized */
  115.         set(App->checkmark1,   MUIA_ShortHelp,"Check me to ignore partial matches");
  116.         set(App->checkmark2,   MUIA_ShortHelp,"case sensitive search");
  117.         set(App->string1,      MUIA_ShortHelp,"Enter search text here");
  118.         set(App->simplebutton1,MUIA_ShortHelp,"Click to start search");
  119.         set(App->simplebutton2,MUIA_ShortHelp,"Click to cancel search");
  120.  
  121.         /* advance from search string to search button with CR */
  122.         set(App->string1, MUIA_String_AdvanceOnCR, TRUE);
  123.         /* Open the applications window */
  124.         set(App->window,MUIA_Window_Open,TRUE);
  125.  
  126.         return(App);
  127. }
  128.  
  129.  
  130.  
  131.